package com.love.marriage.orderInfo.service.impl;

import com.love.marriage.orderInfo.entity.OrderInfo;
import com.love.marriage.orderInfo.vo.OrderInfoVo;
import com.love.marriage.orderInfo.mapper.OrderInfoMapper;
import com.love.marriage.orderInfo.service.OrderInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.love.marriage.userBalanceInfo.service.UserBalanceInfoService;
import com.love.marriage.userMembershipInfo.service.UserMembershipInfoService;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.util.List;
import java.util.Arrays;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import com.love.marriage.utils.StringUtils;

/**
 * <p>
 * description:  订单表服务实现类
 * author:       mybatisPlus
 * createDate:   2024-10-23 22:54:09
 * version:      1.0.0
 */
@Service
@RequiredArgsConstructor
public class OrderInfoServiceImp extends ServiceImpl<OrderInfoMapper, OrderInfo> implements OrderInfoService {

    private final OrderInfoMapper orderInfoMapper;

    @Override
    public Page<OrderInfoVo> getPage(Long pageNum, Long pageSize, OrderInfoVo orderInfoVo) {
        Page<OrderInfoVo> page = new Page<>(pageNum == null ? 1 : pageNum, pageSize == null ? 10 : pageSize);
        return orderInfoMapper.getPage(page, orderInfoVo);
    }

    @Override
    public OrderInfoVo queryOrderInfo(Long id) {
        return orderInfoMapper.queryOrderInfo(id);
    }

    @Override
    public OrderInfoVo queryOrderInfoByOrderNumber(String orderNumber) {
        return orderInfoMapper.queryOrderInfoByOrderNumber(orderNumber);
    }

    @Override
    public OrderInfoVo addOrderInfo(OrderInfoVo orderInfoVo) {
        OrderInfo orderInfo = new OrderInfo();
        BeanUtils.copyProperties(orderInfoVo, orderInfo);
        orderInfoMapper.insert(orderInfo);
        OrderInfoVo res = new OrderInfoVo();
        BeanUtils.copyProperties(orderInfo, res);
        return res;
    }

    @Override
    public OrderInfoVo updateOrderInfo(OrderInfoVo orderInfoVo) {
        OrderInfo orderInfo = new OrderInfo();
        BeanUtils.copyProperties(orderInfoVo, orderInfo);
        orderInfoMapper.updateById(orderInfo);
        return orderInfoVo;
    }

    @Override
    public Boolean deleteOrderInfo(String ids) {
        if(StringUtils.isEmpty(ids)) {
            return true;
        }
        List<String> idArr = Arrays.asList(ids.split(","));
        orderInfoMapper.deleteBatchIds(idArr);
        return true;
    }
}
